﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class web_pages_ajax_tinnhan_page : System.Web.UI.Page
{
    public string act = "", id = "", type = "", mess = "", messok="",del="";
    DataTable dtt;
    public Common comm = new Common();
    string sSelect = "",sWhere="",sFrom="",sql="";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["NTV_id"] == null) mess="Bạn đã hết thời hạn của quyền đăng nhập này, hãy thoát và đăng nhập lại để tiếp tục thao tác!";
        else
        {
            sql = ""; sSelect = ""; sFrom = ""; sWhere = "";
            if (!string.IsNullOrEmpty(Request.Params["actsms"])) act = Request.Params["actsms"];
            if (!string.IsNullOrEmpty(Request.Params["typesms"])) type = Request.Params["typesms"];
            if (!string.IsNullOrEmpty(Request.Params["idsms"])) id = Request.Params["idsms"];
            if (!string.IsNullOrEmpty(Request.Params["del"])) del = Request.Params["del"];
            sSelect = "select * from HeThong_tin_nhan where nguoi_gui='" + Session["NTV_id"] + "'";

            if (type == "0") //Tin tu nha tuyen dung
            {
                sWhere = " kieu_nguoi_gui=1 and nguoi_nhan='"+Session["NTV_id"].ToString() + "'";
                sFrom = "dbo.HeThong_tin_nhan INNER JOIN dbo.DoanhNghiep_doanh_nghiep ON nguoi_gui=ma_doanh_nghiep";
                sSelect = "HeThong_tin_nhan.*,dbo.DoanhNghiep_doanh_nghiep.ten_doanh_nghiep as ten_nguoi_gui,ten_nguoi_nhan=''"+
                ",idnhan='"+Session["NTV_id"]+"',nguoi_gui as idgui";
            }
            else if (type == "1") //Tin tu trung tam GTVL
            {
                sWhere = " kieu_nguoi_gui=3 and nguoi_nhan='" + Session["NTV_id"].ToString() + "'";
                sSelect = "HeThong_tin_nhan.*,ten_nguoi_gui='Trung tâm GTVL Bình Dương',ten_nguoi_nhan=''"+
                    ",idnhan='" + Session["NTV_id"] + "',idgui=''";
                sFrom = "HeThong_tin_nhan";
            }
            else if (type == "2")//Tin da gui
            {
                sWhere = " kieu_nguoi_gui=0 and nguoi_gui='"+Session["NTV_id"].ToString() + "'";
                sFrom = "dbo.HeThong_tin_nhan INNER JOIN dbo.DoanhNghiep_doanh_nghiep ON nguoi_nhan=ma_doanh_nghiep";
                sSelect = "HeThong_tin_nhan.*,dbo.DoanhNghiep_doanh_nghiep.ten_doanh_nghiep as ten_nguoi_nhan,ten_nguoi_gui=''"+
                    ",idgui='" + Session["NTV_id"] + "',nguoi_nhan as idnhan";
            }

            if (act == "0")//Tin chua doc
            { 
                sWhere+=" and da_doc=0";
            }
            else if (act == "1")//Tin da doc
            {
                sWhere += " and da_doc=1";
            }
            else if (act == "2")//Tat ca
            {
                sWhere += " and da_doc IS NOT NULL";
            }
            if (del == "del")
            {
                sql = "delete from HeThong_tin_nhan where id='" + id + "'";
                int i = comm.execNoneQuery(sql);

                //sql = "Select " + sSelect + " from " + sFrom + " where " + sWhere + " order by ngay_gui desc";
                //dtt = comm.getDataTable(sql);
            }
            else if (del == "upd")
            {
                sql = "Update HeThong_tin_nhan set da_doc=1 where id='" + id + "'";
                int i = comm.execNoneQuery(sql);
            }
            sql = "Select " + sSelect + " from " + sFrom + " where " + sWhere + " order by ngay_gui desc";
            dtt = comm.getDataTable(sql);

            rpt_list_obj.DataSource = dtt;
            rpt_list_obj.DataBind();

        }
    }
    protected void rpt_list_obj_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {

    }
}
